<template>
	<view v-if="!is_not_checking">
		该功能已下架...
	</view>
	<view v-else>
		<camera device-position="back" flash="auto" @error="error" style="width: 100%; height: 500upx;">
			<cover-image src="../../static/scan-frame/scan-img.png" class="scan-img"></cover-image>
		</camera>
		
		<!-- <text class="scan-text" style='display: flex'>
			请将<u> {{photo_text}} </u>
			放置白色框内
		</text> -->
		<text>
			请将 <text space="emsp" decode="true" class=photo_text>{{' '}}&emsp;{{photo_text}}&emsp;{{' '}}</text> 放置白色框内
		</text>
		<!-- <textarea class="photo_text">{{photo_text}}</textarea> -->
		<!-- <view style="padding-bottom: 10px;border-bottom-style: solid;border-bottom-style: solid;">
		{{photo_text}}
		</view> -->
		
		<button type="primary" @click="takePhoto">拍照</button>
		<image mode="widthFix" class="photos-box" :src="src"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: "",
				text: "",
				photo_text: "身份证正面(国徽面)",
				is_not_checking: false,
			}
		},
		onLoad(option) {
			
			this.is_not_checking = this.cache.get('is_not_checking');
			
			console.log('onLoad option -------------- ', option);
			this.option = option;
			
			if (option.photo_text) {
				this.photo_text = option.photo_text;
			}
			
			// uni.showModal({
			// 	title: '注意事项',
			// 	content: '为了报名成功, \r\n需要横向的手写电子签名! \r\n签名前请将手机先横过来.',
			// 	// confirmText: "否", 
			// 	showCancel: false,
				
			// 	cancelText: "是",
			// 	success: function(res) {
			// 		console.log('~~~~~~~~~~~ success ', res);
			// 		return
			// 	},
			// 	fail: function(res) {
			// 		console.log('!!!!!!!!!!!!! fail', res);
			// 	}
			// });
		},
		methods: {
			takePhoto() {
				const ctx = uni.createCameraContext();
				ctx.takePhoto({
					quality: 'high',
					success: (res) => {
						this.src = res.tempImagePath
						/* 返回调用页面并把图片URL传递过去 */
						let pages = getCurrentPages();
						let prevPage = pages[pages.length - 2]; 
						let key = this.option.key;
						var dc = {[key]: res.tempImagePath};
						console.log('dc ~~~~~~~ ', dc);
						prevPage.setData(dc);
						
						// let pages = getCurrentPages();
						// let prevPage = pages[pages.length - 2]; 
						// prevPage.setData({
						// 	"image": res.tempImagePath,
						// })
						// console.log('tempImagePath', res.tempImagePath);
						// this.$emit('retMsg', res.tempImagePath);
						uni.navigateBack();
						
						/* 调用页面获取图片URL方法 */
						/* 
						let pages = getCurrentPages();
						let currPage = pages[pages.length-1];
						if(typeof(currPage.data.image) != undefined && currPage.data.image != null){
							console.log('获取图片：', currPage.data.image)
						} 
						*/
					}
				});
			},
			error(e) {
				console.log(e.detail);
			}
		}
	}
</script>

<style>
	.scan-img{
		opacity: 0.4;
		width: 100%;
		height:500upx;
	}
	.scan-text{
		font-size: 20px;
		text-align: center;
		line-height: 60upx;
	}
	.photo_text{
		/* display: flex; */
		/* border-top: 3upx solid #ccc; */
		/* border-bottom: 30upx solid #000; */
		/* padding: 20upx; */
		text-decoration:underline;
	}
</style>
